package com.home.free.util;

import java.io.Serializable;

/**
 * 接口统一返回参数
 * @author gaotianjie
 * @date 2021-01-30
 */
public class Ret<T> implements Serializable {
    private Boolean success;

    private T body;

    private Integer errorCode;

    private String message;

    /**
     * 返回失败的策略
     *
     * @param errorCode
     * @param message
     * @return
     */
    public static <T> Ret<T> retFalse(Integer errorCode, String message) {
        Ret<T> ret = new Ret<>();
        ret.setSuccess(Boolean.FALSE);
        ret.setErrorCode(errorCode);
        ret.setMessage(message);
        return ret;
    }

    /**
     * 返回成功的策略, 有内容
     * @param body
     * @return
     */
    public static <T> Ret<T> retTrue(T body) {
        Ret<T> ret = new Ret<>();
        ret.setSuccess(Boolean.TRUE);
        ret.setBody(body);
        return ret;
    }

    /**
     * 返回成功的策略, 无内容
     * @return
     */
    public static <T> Ret<T> retTrue() {
        Ret<T> ret = new Ret<>();
        ret.setSuccess(Boolean.TRUE);
        return ret;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
